package com.sxran.im.handler;

import cn.hutool.core.collection.CollectionUtil;
import com.sxran.im.bean.ExportGroupReqBody;
import com.sxran.im.bean.ImException;
import com.sxran.im.dao.ImGroupMapper;
import com.sxran.im.info.ImGroup;
import com.sxran.im.service.UserGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class ExportGroupCmdHandler extends AbstractCmdHandler<ExportGroupReqBody>{
    @Resource
    private ImGroupMapper imGroupMapper;
    @Resource
    private UserGroupService userGroupService;

    @Override
    public Object doBeanService(ExportGroupReqBody json) {
        String groupId = json.getGroupId();
        List<String> users = json.getUsers();
        if(CollectionUtil.isEmpty(users)){
            throw new ImException("没有指定用户",500);
        }
        // 获取群聊的用户组信息。
        if (userGroupService.isAdmin(groupId)) {
            // 移除用户。
            userGroupService.removeUser(groupId, users);
        }else{
            throw new ImException("您不是管理员",500);
        }
        return json;
    }
}
